package com.stlm2.controller;

import com.stlm2.core.common.page.PageView;
import com.stlm2.dems.entity.Config;
import com.stlm2.dems.entity.User;
import com.stlm2.dems.service.ActivityService;
import com.stlm2.dems.service.ConfigService;
import com.stlm2.dems.service.UserService;
import com.stlm2.util.codecontent.CodeContent;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by apple on 2017.12.28.
 */
@Controller
@RequestMapping("activityC")
public class ActivityController {

    @Resource
    private ActivityService activityService;
    @Resource
    private UserService userService;


    @RequestMapping("list")
    public ModelAndView list(ModelAndView modelAndView){
        modelAndView.setViewName("/activity/list");
        return modelAndView;
    }

    /**
     *  活动   list
     * ffl
     * 2017-12-28 10:39:53
     * @param token
     * @param name
     * @param label
     * @param activityState
     * @param pageNu
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/search.json",produces="application/json;charset=UTF-8")
    public String search(String token, String name,String label,String activityState,String pageNu){

        String data = null;
        try {
            data = activityService.search(token, name, label, activityState, pageNu);
        } catch (Exception e) {
            e.printStackTrace();
            return CodeContent.getModelByCode(0, "查询失败", data);
        }
        return data;
    }


    /** 编辑 使有效
     * ffl
     * 2017-12-28 13:50:47
     * @param token
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/effective.json",produces="application/json;charset=UTF-8")
    public String effective(String token, String id){

        String data = null;
        try {
            data = activityService.effective(token, id);
        } catch (Exception e) {
            e.printStackTrace();
            return CodeContent.getModelByCode(0, "查询失败", data);
        }
        return data;
    }


    /** 编辑 使无效
     * ffl
     * 2017-12-28 13:50:47
     * @param token
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/invalid.json",produces="application/json;charset=UTF-8")
    public String invalid(String token, String id){
        String data = null;
        try {
            data = activityService.invalid(token, id);
        } catch (Exception e) {
            e.printStackTrace();
            return CodeContent.getModelByCode(0, "查询失败", data);
        }
        return data;
    }


    /**
     *  活动详情
     * ffl
     * 2017-12-28 14:10:38
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/detail.json",produces="application/json;charset=UTF-8")
    public String detail(String id){
        String data = null;
        try {
            data = activityService.detail(id);
        } catch (Exception e) {
            e.printStackTrace();
            return CodeContent.getModelByCode(0, "查询失败", data);
        }
        return data;
    }

    /** 编辑 活动 时间
     * ffl
     * 2017-12-28 15:05:36
     * @param token
     * @param id
     * @param startTime
     * @param endTime
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/edit.json",produces="application/json;charset=UTF-8")
    public String edit(String token, String id,String startTime,String endTime){
        String data = null;
        try {
            data = activityService.edit(token, id, startTime, endTime);
        } catch (Exception e) {
            e.printStackTrace();
            return CodeContent.getModelByCode(0, "查询失败", data);
        }
        return data;
    }
}
